home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-03-29 | 57.7 KB | 1,752 lines |
- ###############################################################
- # Minihelp - Help Editor
- # Charlie KEMPSON - charlie@siren.demon.co.uk
- # http://public.logica.com/~kempsonc
- ###############################################################
-
- ###############################################################
- # This program is free software; you can redistribute it
- # and/or modify it under the terms of the GNU General
- # Public License as published by the Free Software
- # Foundation (version 2 of the License).
- #
- # This program is distributed in the hope that it will
- # be useful, but WITHOUT ANY WARRANTY; without even the
- # implied warranty of MERCHANTABILITY or FITNESS FOR A
- # PARTICULAR PURPOSE. See the GNU General Public License
- # for more details.
- #
- # For a copy of the GNU General Public License, write to the
- # Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
- # MA 02139, USA.
- ###############################################################
-
- ###############################################################
- # Set include path
- set GLOBAL_INCLUDE "/usr/local/lib/TkNet"
- #set GLOBAL_INCLUDE "/home/charlie/TKNET/usr/local/lib/TkNet"
-
- ###############################################################
- # Globals for this module
- set BITMAP_HEIGHT 60
- set BITMAP_WIDTH 40
-
- # Globals
- set g_selected_file ""
- set g_selected_file_filter ""
-
- # Flags
- set gas_pages ""
- set gas_history ""
- set gb_current_page_changed 0
- set gb_project_changed 0
- set gs_current_project ""
- set gs_new_project_name ""
- set gs_MH_NewHelpPage ""
- set gs_cut_buffer ""
- set gb_show_formatted 1
- set gb_keep_old_text 0
- set gb_page_autocommit 1
-
- # Geometry
- set TKNET_HELP_GEOMETRY "+200+200"
- set FIXED_FONT_SMALL -*-courier-medium-r-*-*-*-*-*-*-*-*-*-*
- set FIXED_FONT -*-courier-medium-r-*-*-14-*-*-*-*-*-*-*
- set FONT_SMALL -adobe-helvetica-medium-r-*-*-*-*-*-*-*-*-*-*
- set FONT_NORMAL -adobe-helvetica-medium-r-*-*-14-*-*-*-*-*-*-*
- set FONT_ITALIC -adobe-helvetica-medium-o-*-*-14-*-*-*-*-*-*-*
- set FONT_BOLD -adobe-helvetica-bold-r-*-*-14-*-*-*-*-*-*-*
- set BUTTON_COLOUR Grey65
- set TEXT_COLOUR White
- set DEFAULT_COLOUR Grey75
- set RED Red
- set GREEN ForestGreen
- set LOWER_BORDER 3
- set RIDGE_BORDER 2
- set DEFAULT_PADDING 5
-
- # Set Tk/tcl global variables
- set tk_strictMotif 1
- set tcl_precision 3
-
- ###############################################################
- # Set application defaults
-
- # Fonts
- option add *font $FONT_NORMAL startupFile
-
- # Highlight
- option add *highlightThickness 0
-
- # Colours
- option add *background $DEFAULT_COLOUR startupFile
- option add *Text.background $TEXT_COLOUR startupFile
- option add *Entry.background $TEXT_COLOUR startupFile
-
- ###############################################################
- # The procedure to read other tcl files stored in
- # /usr/local/lib/TkNet/modules
- proc MH_SourceOther { filename } {
-
- # Globals
- global GLOBAL_INCLUDE
-
- # Look in the global area for files
- if [file exists "$GLOBAL_INCLUDE/modules/$filename"] {
- if [catch {uplevel #0 source "$GLOBAL_INCLUDE/modules/$filename"}] {
- MH_InfoDialog . "Error reading file : this doesn't look like a Tcl archive"
- }
- } else {
- # FILE MISSING FROM /usr/local/lib/TkNet/modules
- MH_InfoDialog . "File $filename missing from $GLOBAL_INCLUDE/modules."
- }
- }
-
- ###############################################################
- # Display a blocking information dialog
- proc MH_InfoDialog { parent string } {
-
- # Globals
- global FONT_NORMAL RIDGE_BORDER DEFAULT_PADDING \
- BITMAP_HEIGHT BITMAP_WIDTH
-
- # Display the string to the user
- if [winfo exists .dialog] return
- toplevel .dialog
- wm title .dialog [wm title $parent]
- wm transient .dialog .
- # wm resizable .dialog 0 0
- grab current .dialog
-
- ###############################################################
- # Create the message
- frame .dialog.fr -borderwidth $RIDGE_BORDER -relief groove
- pack .dialog.fr -padx $DEFAULT_PADDING -pady \
- $DEFAULT_PADDING -side top -expand true -fill both
- label .dialog.fr.bitmap -bitmap info -height \
- $BITMAP_HEIGHT -width $BITMAP_WIDTH
- label .dialog.fr.message -text $string -justify left
- pack .dialog.fr.bitmap .dialog.fr.message -side left \
- -anchor w
-
- ###############################################################
- # Create the buttons below the frame
- frame .dialog.button_frame -borderwidth $DEFAULT_PADDING
- pack .dialog.button_frame -side bottom -fill x
- button .dialog.button_frame.dismiss \
- -text Dismiss -command { destroy .dialog }
- pack .dialog.button_frame.dismiss
-
-
- ###############################################################
- # Bind return and space to dismiss
- bind .dialog <Return> {destroy .dialog}
- bind .dialog <space> {destroy .dialog}
-
- ###############################################################
- # Centre the dialog on the parent (was widget $parent)
- MH_CentreDialog .dialog
-
- ###############################################################
- # Wait for the button to be pressed
- tkwait window .dialog
- }
-
- ###############################################################
- # Display a blocking question dialog
- proc MH_QuestionDialog { parent string button1 button2 } {
-
- # Globals
- global FONT_NORMAL RIDGE_BORDER DEFAULT_PADDING \
- BITMAP_HEIGHT BITMAP_WIDTH g_status
-
- # Initialise return status
- set g_status -1
-
- # Display the string to the user
- if [winfo exists .dialog] {return $g_status}
- toplevel .dialog
- wm title .dialog [wm title $parent]
- wm transient .dialog .
- # wm resizable .dialog 0 0
- grab current .dialog
-
- ###############################################################
- # Create the message
- frame .dialog.fr -borderwidth $RIDGE_BORDER -relief groove
- pack .dialog.fr -padx $DEFAULT_PADDING -pady \
- $DEFAULT_PADDING -side top -expand true -fill both
- label .dialog.fr.bitmap -bitmap questhead -height \
- $BITMAP_HEIGHT -width $BITMAP_WIDTH
- label .dialog.fr.message -text $string -justify left
- pack .dialog.fr.bitmap .dialog.fr.message -side left \
- -anchor w
-
- ###############################################################
- # Create the buttons below the frame
- frame .dialog.button_frame -borderwidth $DEFAULT_PADDING
- pack .dialog.button_frame -side bottom -fill x
- button .dialog.button_frame.ok \
- -text $button1 -command {destroy .dialog; set g_status 0}
- button .dialog.button_frame.cancel \
- -text $button2 -command {destroy .dialog; set g_status 1}
- pack .dialog.button_frame.ok .dialog.button_frame.cancel \
- -side right
-
- ###############################################################
- # Centre the dialog on the parent
- MH_CentreDialog .dialog
-
- ###############################################################
- # Wait for the button to be pressed
- tkwait variable g_status
- return $g_status
- }
-
- ###############################################################
- # Display a blocking information dialog
- proc MH_WorkingDialog { parent string } {
-
- # Globals
- global FONT_NORMAL RIDGE_BORDER DEFAULT_PADDING \
- BITMAP_HEIGHT BITMAP_WIDTH
-
- # Display the string to the user
- if [winfo exists .MH_WorkingDialog] return
- set window [toplevel .MH_WorkingDialog]
- wm title .dialog [wm title $parent]
- wm transient $window .
- # wm resizable $window 0 0
- grab current $window
-
- ###############################################################
- # Create the message
- frame $window.fr -borderwidth $RIDGE_BORDER -relief groove
- pack $window.fr -padx $DEFAULT_PADDING -pady \
- $DEFAULT_PADDING -side top -expand true -fill both
- label $window.fr.bitmap -bitmap hourglass -height \
- $BITMAP_HEIGHT -width $BITMAP_WIDTH
- label $window.fr.message -text $string -justify left
- pack $window.fr.bitmap $window.fr.message -side left \
- -anchor w
-
- ###############################################################
- # Centre the dialog on the parent (was widget $parent)
- MH_CentreDialog $window
- update
- }
-
- ###############################################################
- # Centre a window on the screen (or parent)
- proc MH_CentreDialog {window {position ""} {parent ""}} {
-
- # Withdraw dialog and update all windows
- wm withdraw $window
- update idletasks
- set win_width [winfo reqwidth $window]
- set win_height [winfo reqheight $window]
-
- # Read the positioning argument (pointer, widget, default)
- switch -glob -- $position {
- p* {
- # place at POINTER (centered is $a == center)
- wm geometry $window +[expr \
- [winfo pointerx $window]-$win_width \
- /2]+[expr [winfo pointery $window]-\
- $win_height/2]
- }
- w* {
- # center about WIDGET $parent
- wm geometry $window +[expr [winfo rootx $parent]+ \
- ([winfo width $parent]-$win_width)/2]+[expr \
- [winfo rooty $parent]+([winfo height \
- $parent]-$win_height)/2]
- }
- default {
- wm geometry $window +[expr ([winfo screenwidth \
- $window]-$win_width) / 2]+[expr ([winfo screenheight \
- $window]- $win_height) / 2]
- }
- }
-
- # Now show the window
- wm deiconify $window
- }
-
- ###############################################################
- # Create a scrolled text widget
- proc MH_ScrolledText { f width height horiz } {
-
- # Global
- global FIXED_FONT_SMALL
-
- frame $f
- # The setgrid setting allows the window to be resized.
- text $f.text -width $width -height $height \
- -setgrid true -width $width -wrap word \
- -yscrollcommand [list $f.yscroll set] \
- -font $FIXED_FONT_SMALL
- if {$horiz == 1} {
- $f.text configure -xscrollcommand [list \
- $f.xscroll set] -wrap none
- scrollbar $f.xscroll -orient horizontal \
- -command [list $f.text xview]
- pack $f.xscroll -side bottom -fill x
- }
- scrollbar $f.yscroll -orient vertical \
- -command [list $f.text yview]
- pack $f.yscroll -side right -fill y
-
- # The fill and expand are needed when resizing.
- pack $f.text -side left -fill both -expand true
- pack $f -side top -fill both -expand true
- return $f.text
- }
-
- ###############################################################
- # Create a scrolled text widget
- proc MH_ScrolledList { frame width height mode horiz } {
-
- frame $frame
- # The setgrid setting allows the window to be resized.
- listbox $frame.list -width $width -height $height \
- -setgrid true -yscrollcommand [list $frame.yscroll set] \
- -selectmode $mode
- if {$horiz == 1} {
- $frame.list configure -xscrollcommand [list \
- $frame.xscroll set] -wrap none
- scrollbar $frame.xscroll -orient horizontal \
- -command [list $frame.list xview]
- pack $frame.xscroll -side bottom -fill x
- }
- scrollbar $frame.yscroll -orient vertical \
- -command [list $frame.list yview]
- pack $frame.yscroll -side right -fill y
-
- # The fill and expand are needed when resizing.
- pack $frame.list -side left -fill both -expand true
- pack $frame -side top -fill both -expand true
- return $frame.list
- }
-
- ###############################################################
- # The procedure for popping up a popup menu
- proc MH_PopupMenu { parent window } {
-
- # Get current mouse position
- set x [ winfo pointerx $parent ]
- set y [ winfo pointery $parent ]
-
- # Popup the menu
- tk_popup $window $x $y
- }
-
- ###############################################################
- # Change cursor to an hourglass and back again
- proc MH_WatchCursor {} {
-
- # Loop through children setting the cursor
- foreach w [winfo children .] {
- lappend busy [list $w [lindex [$w config -cursor] 4]]
- }
- foreach w $busy {catch {[lindex $w 0] config -cursor watch}}
- update idletasks
- }
- proc MH_NormalCursor {} {
-
- # Loop through children setting the cursor
- foreach w [winfo children .] {
- lappend notbusy [list $w [lindex [$w config -cursor] 4]]
- }
- foreach w $notbusy {catch {[lindex $w 0] config -cursor hand2}}
- update idletasks
- }
-
-
- ###############################################################
- # The procedure for creating images
- proc MH_CreateImage { file } {
-
- # This procedure attempts to create an image from
- # the data specified in the named file. If the
- # file is non-existant, or the image type is not
- # supported, -1 is returned and a dialogue is
- # displayed.
-
- if [file exists $file] {
-
- # Create the image
- set name [join [list $file "_image"] ""]
- if [catch {image create bitmap $name -file $file} text] {
- # Not a bitmap, try pixmap
- if [catch {image create pixmap $name -file $file} text] {
- # Not a pixmap, try gif
- if [catch {image create photo $name -file $file} text] {
- # Give up!
- MH_InfoDialog . "Image $file has an unrecognised type!
- See help on images for more information."
- return -1
- }
- }
- }
- return $name
- } else {
- MH_InfoDialog . "File $file does not exists!"
- return -1
- }
- }
-
- ###############################################################
- # The procedure for selecting a file
- proc MH_FileSelect { {title "Select File"} {filter "*"} } {
-
- # This procedure pops up a file selection box
- # and returns the selected file.
-
- # Globals
- global TEXT_COLOUR DEFAULT_PADDING RIDGE_BORDER \
- g_selected_file g_selected_file_filter
- set g_selected_file_filter $filter
-
- # Popup a selection window
- set window .fileselect
- if [winfo exists $window] {
- # Pop it up!
- wm deiconify $window
- raise $window
- return
- }
-
- # Otherwise create the window
- toplevel $window
- wm title $window $title
- wm transient $window .
-
- # Create a frame containing the filter
- frame $window.filter_fr -borderwidth $RIDGE_BORDER -relief groove
- pack $window.filter_fr -padx $DEFAULT_PADDING -pady $DEFAULT_PADDING \
- -side top -fill x
- label $window.filter_fr.label -text "Filter"
- entry $window.filter_fr.entry -width 15 -bg $TEXT_COLOUR \
- -textvariable g_selected_file_filter
- button $window.filter_fr.filter -text "Filter" -command \
- MH_PopulateFileSelect
- pack $window.filter_fr.label $window.filter_fr.entry \
- $window.filter_fr.filter -side left \
- -padx $DEFAULT_PADDING -pady $DEFAULT_PADDING
-
- # Create the directory list and file list
- frame $window.list_fr
- pack $window.list_fr -fill both -expand true
- set dirlist [MH_ScrolledList $window.list_fr.dir_fr 0 10 browse 0]
- set filelist [MH_ScrolledList $window.list_fr.file_fr 0 10 browse 0]
- $dirlist configure -bg $TEXT_COLOUR
- $filelist configure -bg $TEXT_COLOUR
- pack forget $window.list_fr.dir_fr $window.list_fr.file_fr
- pack $window.list_fr.dir_fr $window.list_fr.file_fr -side left -fill \
- both -padx $DEFAULT_PADDING -pady $DEFAULT_PADDING \
- -expand true
-
- # Create a frame to display the current directory
- frame $window.dir_fr -borderwidth $RIDGE_BORDER -relief groove
- pack $window.dir_fr -padx $DEFAULT_PADDING -pady $DEFAULT_PADDING \
- -side top -fill x
- label $window.dir_fr.label -text "Directory : "
- label $window.dir_fr.dir
- pack $window.dir_fr.label $window.dir_fr.dir -side left \
- -padx $DEFAULT_PADDING -pady $DEFAULT_PADDING -fill x
-
- # Create a frame containing an entry field
- frame $window.sel_fr -borderwidth $RIDGE_BORDER -relief groove
- pack $window.sel_fr -padx $DEFAULT_PADDING -pady $DEFAULT_PADDING \
- -side top -fill x
- label $window.sel_fr.label -text "File"
- set entry [entry $window.sel_fr.entry -width 30 -bg $TEXT_COLOUR]
- pack $window.sel_fr.label $window.sel_fr.entry -side left \
- -padx $DEFAULT_PADDING -pady $DEFAULT_PADDING -fill x
-
- # And add buttons to the window
- set frame [frame $window.button_fr]
- pack $frame -side bottom -fill x
- button $frame.close -text Cancel -command {
- destroy .fileselect
- set g_selected_file ""
- }
- button $frame.ok -text OK -command {
- set file [.fileselect.sel_fr.entry get]
- set dir [pwd]
- set g_selected_file "$dir/$file"
- destroy .fileselect
- }
- bind $window.sel_fr.entry <Return> "$frame.ok invoke"
- pack $frame.ok $frame.close -side right -padx $DEFAULT_PADDING -pady \
- $DEFAULT_PADDING
-
- # Retrieve the list
- MH_PopulateFileSelect
-
- # And now centre it on its parent
- MH_CentreDialog $window widget .
- focus $window.sel_fr.entry
-
- # Add bindings on list
- bind $dirlist <Double-ButtonRelease-1> {
- set page [.fileselect.list_fr.dir_fr.list get \
- [.fileselect.list_fr.dir_fr.list curselection]]
- if {$page == ".."} {cd ..} else {cd $page}
- MH_PopulateFileSelect
- }
- bind $filelist <Double-ButtonRelease-1> {
- set page [.fileselect.list_fr.file_fr.list get \
- [.fileselect.list_fr.file_fr.list curselection]]
- after 400 destroy .fileselect
- set dir [pwd]
- set g_selected_file "$dir/$page"
- }
- bind $filelist <ButtonRelease-1> {
- set page [.fileselect.list_fr.file_fr.list get \
- [.fileselect.list_fr.file_fr.list curselection]]
- .fileselect.sel_fr.entry delete 0 end
- .fileselect.sel_fr.entry insert end "$page"
- }
-
- # Wait for destruction of window
- tkwait variable g_selected_file
- return $g_selected_file
- }
-
- ###############################################################
- # The procedure for selecting a file
- proc MH_PopulateFileSelect { } {
-
- # Globals
- global g_selected_file_filter
- set filter $g_selected_file_filter
-
- # Retrieve new information
- set files [lsort [glob -nocomplain $filter]]
- set dirs [lsort [glob -nocomplain "*"]]
- .fileselect.list_fr.dir_fr.list delete 0 end
- .fileselect.list_fr.dir_fr.list insert end ".."
- .fileselect.list_fr.file_fr.list delete 0 end
-
- # Loop through returned items
- foreach file $files {
- if ![file isdirectory $file] {
- .fileselect.list_fr.file_fr.list insert end $file
- }
- }
- foreach file $dirs {
- if [file isdirectory $file] {
- .fileselect.list_fr.dir_fr.list insert end $file
- }
- }
-
- # Set the current directory
- .fileselect.dir_fr.dir configure -text [pwd]
- }
-
- ###############################################################
- # Procedure to open a help file
- proc MH_OpenProject { } {
-
- # Globals
- global RIDGE_BORDER DEFAULT_PADDING TEXT_COLOUR \
- gb_current_page_changed gb_project_changed \
- gs_current_project
-
- # Check for changes to the project
- if {$gb_current_page_changed || $gb_project_changed} {
- if [MH_QuestionDialog . "The project has changed. Do
- you wish to discard changes?" "Discard" "Cancel"] {
- # User requested cancel
- return
- }
- }
-
- # Prompt for the project to open
- set gs_current_project [MH_FileSelect "Open Project"]
- if {$gs_current_project != ""} {MH_ReadProject}
- }
-
- ###############################################################
- # Procedure to open a help file
- proc MH_ReadProject { } {
-
- # Globals
- global gas_pages gs_current_project gas_history \
- gt_mini_help gb_current_page_changed \
- gb_project_changed
-
- # Get the file name
- set file $gs_current_project
- if {[file exists $file] == 1} {
- # If current information exists, delete it.
- set current_pages [info globals "gs_HELPTEXT_*"]
- foreach page $current_pages {
- global $page
- unset $page
- }
-
- # Blank old information
- $gt_mini_help configure -state normal
- $gt_mini_help delete 1.0 end
- $gt_mini_help configure -state disabled
- .name_fr.name configure -state normal
- .name_fr.name delete 0 end
- .name_fr.name configure -state disabled
-
- # Source the new file
- if [catch {uplevel #0 "source $file"}] {
- # Error reading file - probably not a help archive
- MH_InfoDialog . "File does not have the correct format.
- Are you sure that this is a valid halp archive?"
- set gs_current_project ""
- return
- }
-
- # Build up a list of new pages
- set gas_pages [info globals "gs_HELPTEXT_*"]
- set gas_history ""
- set gb_current_page_changed 0
- set gb_project_changed 0
-
- # Display the page selector
- MH_SelectHelpPage FULL
-
- # Save the project name
- wm title . "Edit Help - $file"
-
- } else {
- # File does not exist
- MH_InfoDialog . " File $file does not exist"
- set gs_current_project ""
- }
- }
-
- ###############################################################
- # Procedure to save a help file
- proc MH_SaveProject { {name ""} } {
-
- # Globals
- global gas_pages gb_project_changed gb_page_autocommit \
- gb_current_page_changed gs_current_project
-
- # Check the name for syntactic correctness
- if {[llength [split $name]] > 1 || [regexp -nocase \
- {[`|!$%^&*()|~<>,]+} $name] || $name == ""} {
- MH_InfoDialog . "Chosen name is not valid.
- The project has not been saved."
- return
- }
-
- # If project does not have a name pop
- # up the save project as dialog.
- if {$name == ""} {
- MH_SaveProjectAs
- return
- }
-
- # If the current page has been changed, ask the user if
- # (s)he wishes to save the changes to the current page
- # before saving.
- if {$gb_current_page_changed == 1} {
- if {$gb_page_autocommit == 1 || [MH_QuestionDialog . \
- "The current page has changed. Do you wish
- to save these changes with the project?" "No" "Yes"]} {
- MH_SaveHelpPage
- }
- }
-
- # Open the file
- if [catch {set fp [open $name w]}] {
- MH_InfoDialog . "Unable to open file $name for writing"
- return
- }
-
- # Write the header
- puts $fp "###############################################################
- #
- # THIS FILE WAS PRODUCES USING MINI HELP VERSION 1.0
- #
- # The file may be edited by hand but is best and most
- # easily editied using the mini-help editor.
- #
- # The help text uses a minor subset of the html command
- # language. The following constructs are supported:
- #
- # <TITLE> Text </TITLE> - Centre's, bolds and underlines
- # <XREF gs_help_string_ref> Text </XREF> - Hyperlinks
- #
- # <B> Text </B> - Bold
- # <I> Text </I> - Italic
- # <TT> Text </TT> - Sans serif
- # <UL> Text </UL> - Underline
- #
- # <CENTER> Text </CENTER> - Centre Justify
- # <LEFT> Text </LEFT> - Left Justify
- # <RIGHT> Text </RIGHT> - Right Justify
- #
- ###############################################################
-
- "
- # Now write the help text itself
- foreach page $gas_pages {
- global $page
- set text [eval subst \$$page]
- puts $fp "global $page
- set $page \\
- \\
- \"$text\"
- "
- }
-
- # Flush the file
- flush $fp
- close $fp
-
- # Inform the user
- MH_InfoDialog . "Help saved to file $name"
- set gb_project_changed 0
- set gs_current_project $name
- wm title . "Edit Help - $name"
- }
-
- ###############################################################
- # Procedure to save a help file
- proc MH_SaveProjectAs { } {
-
- # Globals
- global RIDGE_BORDER DEFAULT_PADDING gs_new_project_name \
- TEXT_COLOUR
-
- # Prompt for the project to save as
- set gs_new_project_name [MH_FileSelect "Save Project As..."]
- if [file exists $gs_new_project_name] {
- if [MH_QuestionDialog . "Are you sure you wish to overwrite
- file $gs_new_project_name ?" "Yes" "No"] {
- MH_InfoDialog . "Help not saved"
- return
- }
- }
-
- # Check validity of name
- if {$gs_new_project_name != ""} {
- MH_SaveProject $gs_new_project_name
- } else {
- MH_InfoDialog . "You must choose a name for
- your new help archive!"
- }
- }
-
- ###############################################################
- # Procedure to close a help file
- proc MH_CloseProject { b_exit } {
-
- # Globals
- global gb_current_page_changed gb_project_changed gas_pages \
- gs_current_project gs_new_project_name gs_MH_NewHelpPage \
- gt_mini_help
-
- # Check for changes to the project
- if {$gb_current_page_changed || $gb_project_changed} {
- if [MH_QuestionDialog . "The project has changed. Do
- you wish to discard changes?" "Discard" "Cancel"] {
- # User requested cancel
- return
- }
- }
-
- # Rest all variables, and destroy all globals
- foreach page $gas_pages {
- global $page
- unset $page
- }
- set gas_pages ""
- set gb_current_page_changed 0
- set gb_project_changed 0
- set gs_current_project ""
- set gs_new_project_name ""
- set gs_MH_NewHelpPage ""
- wm title . "Edit Help - <no project>"
-
- # Reset all user fields
- $gt_mini_help configure -state normal
- $gt_mini_help delete 1.0 end
- $gt_mini_help configure -state disabled
- .name_fr.name configure -state normal
- .name_fr.name delete 0 end
- .name_fr.name configure -state disabled
-
- # If the argument is 1, the user is trying to exit
- if {$b_exit == 1} {destroy .}
- }
-
- ###############################################################
- # The procedure to let you select a page
- proc MH_SelectHelpPage { type } {
-
- # Type may be HISTORY or FULL
-
- # Globals
- global RIDGE_BORDER DEFAULT_PADDING TEXT_COLOUR \
- gas_history gas_pages
-
- # Test for window
- # Popup a selection window
- set window .select_help
- if [winfo exists $window] {
- # Pop it up!
- wm deiconify $window
- raise $window
- update
- return
- }
-
- toplevel $window
- if {$type == "HISTORY"} {
- wm title $window "History"
- set as_list $gas_history
- } else {
- wm title $window "Select Page"
- set as_list $gas_pages
- }
- wm transient $window .
-
- # Create a frame containing a list
- frame $window.sel_fr -borderwidth $RIDGE_BORDER -relief groove
- pack $window.sel_fr -padx $DEFAULT_PADDING -pady $DEFAULT_PADDING \
- -side top -fill x
- set list [MH_ScrolledList $window.list_fr 0 10 browse 0]
- $list configure -bg $TEXT_COLOUR
- pack forget $window.list_fr
- pack $window.list_fr -side top -fill both -padx $DEFAULT_PADDING \
- -pady $DEFAULT_PADDING -expand true
-
- # Add the help pages title to the list
- foreach item $as_list {
- # Get the help text title for the page
- set text "Unknown Help Page"
- global $item
- set local_text [eval subst {\$$item}]
- set start [string first "<title>" $local_text]
- if {$start == -1} {set start [string first "<TITLE>" $local_text]}
- set end [string first "</title>" $local_text]
- if {$end == -1} {set end [string first "</TITLE>" $local_text]}
-
- if {$start != -1} {
- set start [expr [string wordend $local_text [expr $start + 1]] +1]
- set end [expr [string wordstart $local_text $end] -1]
- set text [string range $local_text $start $end]
- set text [string trimleft $text]
- } else {
- MH_InfoDialog . "Error in help text (${item})!
- All pages must begin with a title e.g.
- <title>Contents</title> or
- <TITLE>Contents</TITLE>"
- }
- $list insert end $text
- }
-
- # Now for a goto, close and contents button
- set frame [frame $window.button_fr]
- pack $frame -side bottom -fill x
- button $frame.close -text Close -command "destroy $window"
- button $frame.new -text New -command "destroy $window; MH_NewHelpPage"
- button $frame.goto -text Goto -command "MH_SelectPageFromList $type"
- bind $list <Double-ButtonRelease-1> "MH_SelectPageFromList $type"
- pack $frame.close $frame.new $frame.goto -side right \
- -padx $DEFAULT_PADDING -pady $DEFAULT_PADDING
-
- # And now centre it on its parent
- MH_CentreDialog $window widget .
- }
-
- ###############################################################
- # The procedure to navigate backwards through the history
- proc MH_SelectPageFromList { type } {
-
- # Globals
- global gas_history gas_pages
-
- set page [.select_help.list_fr.list curselection]
- if {$page == ""} {
- return
- } else {
-
- # Type may be HISTORY or FULL
- if {$type == "HISTORY"} {
- set as_list $gas_history
- } else {
- set as_list $gas_pages
- }
-
- set name [lindex $as_list $page]
- if {$type == "HISTORY"} {set gas_history \
- [lreplace $gas_history $page end]}
- MH_DisplayHelpPage $name
- after 400 destroy .select_help
- }
- }
-
- ###############################################################
- # The procedure to navigate backwards through the history
- proc MH_EditNavigateBack {} {
-
- # Globals
- global gas_history
-
- # The list gas_history contains a list of all help pages
- # visited. Simply extract the second to last page, and
- # delete the last item in the list, then dislpay the
- # page.
- # MH_InfoDialog . $gas_history
- if {[llength $gas_history] < 2} {
- # Nowhere to return to
- return
- }
-
- # Get the last page
- set help [lindex $gas_history [expr [llength $gas_history] - 2]]
-
- # Delete the two last items (note that one of them is recreated
- # when we call MH_DisplayHelpPage).
- set gas_history [lreplace $gas_history [expr [llength $gas_history] \
- - 2] end]
-
- # And show the help page
- MH_DisplayHelpPage $help
- }
-
- ###############################################################
- # Procedure for displaying a help page
- proc MH_DisplayHelpPage { text } {
-
- # Globals
- global gt_mini_help gas_pages gb_current_page_changed \
- gas_history
-
- # Check for the existence of the page before going
- # ahead...
- if {[info globals $text] == ""} {
- MH_InfoDialog . "Page does not exist!"
- return
- }
-
- # Display the associated help text
- $gt_mini_help configure -state normal
- $gt_mini_help delete 1.0 end
- global $text
- $gt_mini_help insert end [eval subst \$$text]
- # Parse the help (0=Edit rather than run time)
- MH_ParseHelp 0
- set gb_current_page_changed 0
-
- # Set the focus
- focus $gt_mini_help
-
- # Display the page title in the entry
- .name_fr.name configure -state normal
- .name_fr.name delete 0 end
- .name_fr.name insert end [string range $text 12 end]
- .name_fr.name configure -state disabled
- .name_fr.save configure -state disabled
-
- # Add to the history list (removing any other references to
- # the page on the way - there will be at most one given the
- # nature of the check)
- set item [lsearch -exact $gas_history $text]
- if {$item != -1} {set gas_history [lreplace $gas_history $item $item]}
- lappend gas_history $text
- }
-
- ###############################################################
- # Procedure for displaying a new help page
- proc MH_NewHelpPage { } {
-
- # If the variable keep_old_text is set, then
- # the text that is currently being displayed
- # is retained.
-
- # Globals
- global RIDGE_BORDER DEFAULT_PADDING gs_MH_NewHelpPage \
- gt_mini_help gas_pages TEXT_COLOUR gb_keep_old_text \
- gas_history
-
- # Popup a selection window
- set window .new_page
- if [winfo exists $window] {
- # Pop it up!
- wm deiconify $window
- raise $window
- return
- }
-
- # Otherwise create the window
- toplevel $window
- wm title $window "New Help Page"
- wm transient $window .
-
- # Create a frame containing a list and an entry field
- frame $window.sel_fr -borderwidth $RIDGE_BORDER -relief groove
- pack $window.sel_fr -padx $DEFAULT_PADDING -pady $DEFAULT_PADDING \
- -side top -fill x
- label $window.sel_fr.label -text "Page Name"
- entry $window.sel_fr.entry -width 30 -bg $TEXT_COLOUR -textvariable \
- gs_MH_NewHelpPage
- pack $window.sel_fr.label $window.sel_fr.entry -side left \
- -padx $DEFAULT_PADDING -pady $DEFAULT_PADDING
-
- # And add buttons to the window
- set frame [frame $window.button_fr]
- pack $frame -side bottom -fill x
- button $frame.close -text Cancel -command "wm withdraw $window"
- button $frame.ok -text OK -command {
- # Check the name for syntactic correctness
- if {[llength [split $gs_MH_NewHelpPage]] > 1 || [regexp -nocase \
- {[`"#;:',.?/\|!$%^&*()|~<>,]+} $gs_MH_NewHelpPage] ||
- $gs_MH_NewHelpPage == ""} {
- MH_InfoDialog . "Chosen name is not valid. Please input
- another name. It must contain only alphanumeric
- characters."
- } else {
- # Create a new global
- set variable "gs_HELPTEXT_$gs_MH_NewHelpPage"
- global $variable
- set $variable ""
- lappend gas_pages $variable
- lappend gas_history $variable
-
- # Clear the text area
- $gt_mini_help configure -state normal
- if {$gb_keep_old_text == 0} {
- $gt_mini_help delete 1.0 end
- } else {
- # Reset flag
- set gb_keep_old_text 0
- }
-
- # Display the page title in the entry
- .name_fr.name configure -state normal
- .name_fr.name delete 0 end
- .name_fr.name insert end $gs_MH_NewHelpPage
- .name_fr.name configure -state disabled
-
- # Set the focus
- focus $gt_mini_help
-
- # Page should be saved (project has changed)
- .name_fr.save configure -state normal
- set gb_current_page_changed 1
-
- # Withdraw this window
- wm withdraw .new_page
- }
- }
- bind $window.sel_fr.entry <Return> "$frame.ok invoke"
- pack $frame.ok $frame.close -side right -padx $DEFAULT_PADDING -pady \
- $DEFAULT_PADDING
-
- # And now centre it on its parent
- MH_CentreDialog $window widget .
- focus $window.sel_fr.entry
- }
-
- ###############################################################
- # The procedure for finding tags in the help
- proc MH_ShowHyperMenu { tag } {
-
- # Globals
- global gt_mini_help
-
- # Create the menu - Check for existence
- set window .hyper_popup_menu
- if [winfo exists $window] {destroy $window}
-
- # Find the start and end of the current tag
- set x [ winfo pointerx $gt_mini_help ]
- set y [ winfo pointery $gt_mini_help ]
- set curpos [$gt_mini_help index @$x,$y]
- set ranges [$gt_mini_help tag ranges $tag]
- set list_len [llength $ranges]
- for {set count 0} {$count < $list_len} {incr count 2} {
- if {$curpos >= [lindex $ranges $count]} {
- set start [lindex $ranges $count]
- set end [lindex $ranges [expr $count + 1]]
- #MH_InfoDialog . "Tag found $start $end"
- }
- }
-
- # Create the popup menu
- menu .hyper_popup_menu -tearoff 0
- $window add checkbutton -label [string range $tag 12 end] \
- -indicatoron False
- $window add separator
- $window add command -label "Open Link" -command "MH_OpenLink \
- $tag" -underline 0
- $window add command -label "Bind Link" -command "MH_BindLink \
- $tag $start $end" -underline 0
-
- # Now popup the window in place
- MH_PopupMenu . $window
- }
-
- ###############################################################
- # The procedure for finding tags in the help
- proc MH_BindLink { tag start end } {
-
- # Globals
- global gas_pages RIDGE_BORDER \
- DEFAULT_PADDING TEXT_COLOUR gt_mini_help
-
- # Test for NULL arguments. If so, use current
- # selection...
- if {$start == ""} {
- # MH_InfoDialog . "Using current selection"
- if [catch {$gt_mini_help get sel.first}] {return}
- set start [$gt_mini_help index sel.first]
- set end [$gt_mini_help index sel.last]
-
- # Ensure that the current selection has not
- # already got a hyperlink tag
- MH_RemoveTags XREF
- }
- if {$tag == ""} {set tag NONE}
-
- # Test for window
- # Popup a selection window
- set window .bind_hyperlink
- if [winfo exists $window] {destroy $window}
- toplevel $window
- wm title $window "Select Hyperlink"
- wm transient $window .
-
- # Create a frame containing a list
- frame $window.sel_fr -borderwidth $RIDGE_BORDER -relief groove
- pack $window.sel_fr -padx $DEFAULT_PADDING -pady $DEFAULT_PADDING \
- -side top -fill x
- set list [MH_ScrolledList $window.list_fr 0 10 browse 0]
- $list configure -bg $TEXT_COLOUR
- pack forget $window.list_fr
- pack $window.list_fr -side top -fill both -padx $DEFAULT_PADDING \
- -pady $DEFAULT_PADDING -expand true
-
- # MH_InfoDialog . $gas_pages
- # Add the help pages title to the list
- foreach item $gas_pages {
- # Get the help text title for the page
- set text "Unknown Help Page"
- global $item
- set local_text [eval subst {\$$item}]
- set p1 [string first "<title>" $local_text]
- if {$p1 == -1} {set p1 [string first "<TITLE>" $local_text]}
- set p2 [string first "</title>" $local_text]
- if {$p2 == -1} {set p2 [string first "</TITLE>" $local_text]}
-
- if {$p1 != -1} {
- set p1 [expr [string wordend $local_text [expr $p1 + 1]] +1]
- set p2 [expr [string wordstart $local_text $p2] -1]
- set text [string range $local_text $p1 $p2]
- set text [string trimleft $text]
- } else {
- MH_InfoDialog . "Error in help text (${item})!
- All pages must begin with a title e.g.
- <title>Contents</title> or
- <TITLE>Contents</TITLE>"
- }
- set page [string range $item 12 end]
- $list insert end "$text - $page"
- }
-
- # Now for a goto, close and contents button
- set frame [frame $window.button_fr]
- pack $frame -side bottom -fill x
- button $frame.cancel -text Cancel -command "destroy $window"
- button $frame.bind -text OK -command "MH_Create_Link $tag $start $end"
- pack $frame.cancel $frame.bind -side right \
- -padx $DEFAULT_PADDING -pady $DEFAULT_PADDING
-
- # And now centre it on its parent
- MH_CentreDialog $window widget .
- }
-
- ###############################################################
- # The procedure for opening a tag in the help
- proc MH_Create_Link { tag start end } {
-
- # Globals
- global gt_mini_help gas_pages RED GREEN FONT_BOLD \
- gb_current_page_changed gb_project_changed
-
- set page [.bind_hyperlink.list_fr.list curselection]
- if {$page == ""} {
- return
- } else {
- set name [lindex $gas_pages $page]
- if {$tag != "NONE"} {
- $gt_mini_help tag remove $tag $start $end
- }
- $gt_mini_help tag add $name $start $end
- $gt_mini_help tag configure $name -foreground \
- $GREEN -font $FONT_BOLD
- $gt_mini_help tag bind $name <Enter> \
- "$gt_mini_help tag configure $name -foreground $RED"
- $gt_mini_help tag bind $name <Leave> \
- "$gt_mini_help tag configure $name -foreground $GREEN"
- $gt_mini_help tag bind $name <ButtonPress> "MH_ShowHyperMenu $name"
-
- # Page has changed
- set gb_project_changed 1
- set gb_current_page_changed 1
- .name_fr.save configure -state normal
-
- # Destroy the popup
- destroy .bind_hyperlink
- }
- }
-
- ###############################################################
- # The procedure for opening a tag in the help
- proc MH_OpenLink { tag } {
-
- # Globals
- global gb_current_page_changed gb_page_autocommit
-
- # Check for changed
- if {$gb_current_page_changed == 0 || $gb_page_autocommit == 1} {
- MH_SaveHelpPage
- MH_DisplayHelpPage $tag
- } else {
- if ![MH_QuestionDialog . "Help text on this page has changed!" \
- "Discard Changes" "Cancel"] {
- MH_DisplayHelpPage $tag
- }
- }
- }
-
- ###############################################################
- # The procedure for finding tags in the help
- proc MH_RenamePage { } {
-
- # Global
- global gb_keep_old_text gas_history gas_pages
-
- # Popup a warning dialogue
- MH_InfoDialog . "All references to this page must be regenerated!"
-
- # All we need do is to call MH_NewHelpPage, asking the
- # routine to retain the current information. Then
- # we delete the old variable reference.
- set gb_keep_old_text 1
- set name [.name_fr.name get]
- set name "gs_HELPTEXT_$name"
- global $name
- unset $name
-
- # Delete from history, and delete from list of pages
- set location [lsearch -exact $gas_pages $name]
- if {$location != -1} {
- set gas_pages [lreplace $gas_pages $location $location]
- }
- set location [lsearch -exact $gas_history $name]
- if {$location != -1} {
- set gas_history [lreplace $gas_history $location $location]
- }
-
- # Create the new page
- MH_NewHelpPage
- # Fill the field with default information, and
- # disable the cancel button
- wm title .new_page "Rename Page"
- .new_page.sel_fr.entry delete 0 end
- .new_page.sel_fr.entry insert end [.name_fr.name get]
- pack forget .new_page.button_fr.close
- }
-
- ###############################################################
- # The procedure for finding tags in the help
- proc MH_Create_Help { } {
-
- # Globals
- global gt_mini_help search FONT_BOLD FONT_ITALIC \
- FIXED_FONT TEXT_COLOUR
-
- # Format list
- set format_list [list TITLE BOLD ITALIC FIXED UNDERLINE CENTER \
- LEFT RIGHT]
-
- # Keyworks
- set TITLE "TITLE"
- set BOLD "B"
- set ITALIC "I"
- set FIXED "TT"
- set UNDERLINE "U"
- set CENTER "CENTER"
- set LEFT "LEFT"
- set RIGHT "RIGHT"
-
- # Loop round the declared types
- foreach type $format_list {
- # Note that location here is a two element list
- set location [$gt_mini_help tag nextrange $type 1.0]
- set format [eval subst \$$type]
- # MH_InfoDialog . $location
- while {$location != ""} {
- # Replace the tagged area with the formatting
- # instructions
- $gt_mini_help tag remove $type [lindex $location 0] \
- [lindex $location 1]
- $gt_mini_help insert [lindex $location 1] "</$format>"
- $gt_mini_help insert [lindex $location 0] "<$format>"
- set location [$gt_mini_help tag nextrange $type 1.0]
- }
- }
-
- # Now save the hyperlinks - get a tag list and extract
- # all non-hyperlink tags.
- set tags [$gt_mini_help tag names]
- lappend format_list sel
- foreach format $format_list {
- while {[lsearch -exact $tags $format] != -1} {
- set position [lsearch -exact $tags $format]
- set tags [lreplace $tags $position $position]
- }
- }
- #MH_InfoDialog . $tags
- foreach type $tags {
- # For each range in question, tag the selection
- set location [$gt_mini_help tag nextrange $type 1.0]
- # MH_InfoDialog . $location
- while {$location != ""} {
- # Replace the tagged area with the formatting
- # instructions
- $gt_mini_help tag remove $type [lindex $location 0] \
- [lindex $location 1]
- $gt_mini_help insert [lindex $location 1] "</XREF>"
- $gt_mini_help insert [lindex $location 0] "<XREF $type>"
- set location [$gt_mini_help tag nextrange $type 1.0]
- }
- }
-
- # Disable text by default
- $gt_mini_help configure -state disabled
- }
-
- ###############################################################
- # The procedure for finding tags in the help
- proc MH_SaveHelpPage { } {
-
- # Globals
- global gt_mini_help gb_current_page_changed \
- gb_show_formatted
-
- # Create the tagged text
- MH_Create_Help
-
- # Now save to the variable
- set name [.name_fr.name get]
- set name "gs_HELPTEXT_$name"
- global $name
- set text [$gt_mini_help get 1.0 end]
- set $name $text
-
- # If show is true, redisplay the text in formatted form.
- # Otherwise, leave unformatted.
- if {$gb_show_formatted == 1} {
- # Now redisplay the text and disable the save button
- $gt_mini_help configure -state normal
- MH_ParseHelp 0
- }
-
- # Reset status
- .name_fr.save configure -state disabled
- set gb_current_page_changed 0
- }
-
- ###############################################################
- # The procedure for finding tags in the help
- proc MH_DeleteHelpPage { name } {
-
- # Globals
- global gas_pages gt_mini_help gb_current_page_changed \
- gb_project_changed
- set page "gs_HELPTEXT_$name"
- global $page
-
- # Ask the user for confirmation
- if ![MH_QuestionDialog . "Do you really want to delete page '$name'?" \
- "Delete" "Cancel"] {
- # Perform deletion.
- unset $page
- set item [lsearch -exact $gas_pages $page]
- set gas_pages [lreplace $gas_pages $item $item]
- set gas_history [lreplace $gas_history $item $item]
-
- # And blank out the edit areas of the screen
- $gt_mini_help configure -state normal
- $gt_mini_help delete 1.0 end
- $gt_mini_help configure -state disabled
- set gb_current_page_changed 0
- set gb_project_changed 1
-
- # Display the page title in the entry
- .name_fr.name configure -state normal
- .name_fr.name delete 0 end
- .name_fr.name configure -state disabled
- .name_fr.save configure -state disabled
- }
- }
-
- ###############################################################
- # The procedure to goto a specified page from the history
- proc MH_CopyText { delete } {
-
- # Global
- global gt_mini_help gs_cut_buffer
-
- # Copy the selected text into the cut buffer, then
- # delete if the flag 'delete' is set.
- if [catch {$gt_mini_help get sel.first}] {return}
- set gs_cut_buffer [$gt_mini_help get sel.first sel.last]
-
- # And delete/allow a save if data deleted
- if {$delete == 1} {
- $gt_mini_help delete sel.first sel.last
- set gb_project_changed 1
- set gb_current_page_changed 1
- .name_fr.save configure -state normal
- }
- }
-
- ###############################################################
- # The procedure to goto a specified page from the history
- proc MH_PasteText { } {
-
- # Global
- global gt_mini_help gs_cut_buffer
-
- # Perform paste if data exists in the cut buffer
- if {$gs_cut_buffer != ""} {
- set position [$gt_mini_help index insert]
- $gt_mini_help insert $position $gs_cut_buffer
- }
- }
-
- ###############################################################
- # The procedure to add a tag to the current selection
- proc MH_AddTag { type } {
-
- # Globals
- global gt_mini_help search FONT_BOLD FONT_ITALIC \
- FIXED_FONT TEXT_COLOUR RED GREEN gb_project_changed \
- gb_current_page_changed
-
- # Format list
- set format_list [list TITLE BOLD ITALIC FIXED UNDERLINE CENTER \
- LEFT RIGHT]
-
- # If the input argument is not in this list then it is
- # not a valid type.
- if {[lsearch -exact $format_list $type] == -1} {
- MH_InfoDialog . "Invalid/unknown tag type specified!"
- return
- }
-
- # Keyworks and formatting
- set TITLE "TITLE"
- set TITLE_FORMAT "-font $FONT_BOLD -underline True -justify center"
- set BOLD "B"
- set BOLD_FORMAT "-font $FONT_BOLD"
- set ITALIC "I"
- set ITALIC_FORMAT "-font $FONT_ITALIC"
- set FIXED "TT"
- set FIXED_FORMAT "-font $FIXED_FONT"
- set UNDERLINE "U"
- set UNDERLINE_FORMAT "-underline True"
- set CENTER "CENTER"
- set CENTER_FORMAT "-justify center"
- set LEFT "LEFT"
- set LEFT_FORMAT "-justify left"
- set RIGHT "RIGHT"
- set RIGHT_FORMAT "-justify right"
-
- # Get the selected text, and format with the
- # characteristic given, flagging the block with
- # the tag. Check for a selection first.
- if [catch {$gt_mini_help get sel.first}] {return}
-
- # Certain tags preclude other tags (e.g. justification)
- if {$type == "CENTER" || $type == "LEFT" || $type == "RIGHT"} {
- MH_RemoveTags JUSTIFY
- }
-
- # Add the new tag type
- $gt_mini_help tag add $type sel.first sel.last
- set format [eval subst \$${type}_FORMAT]
- eval $gt_mini_help tag configure $type $format
- $gt_mini_help tag raise $type
-
- # And allow a save
- set gb_project_changed 1
- set gb_current_page_changed 1
- .name_fr.save configure -state normal
- }
-
- ###############################################################
- # The procedure to remove all tags from the current selection
- proc MH_RemoveTags { type } {
-
- # Global
- global gt_mini_help FIXED_FONT gb_project_changed \
- gb_current_page_changed
-
- # Allowable values for type are:
- # XREF - Hyperlink references
- # CHARACTER - Character/font formatting
- # JUSTIFY - Justification
- # ALL - All formatting
-
- set as_character [list BOLD UNDERLINE TITLE ITALIC FIXED]
- set as_justify [list CENTER LEFT RIGHT]
- set as_non_xref [list BOLD UNDERLINE TITLE ITALIC FIXED \
- CENTER LEFT RIGHT sel]
- set delete_xref 0
- set al_del_list ""
-
- # Determine what needs to be done
- switch -exact $type {
- XREF {set delete_xref 1}
- CHARACTER {set al_del_list $as_character}
- JUSTIFY {set al_del_list $as_justify}
- ALL {set al_del_list [list [join $as_character $as_justify]]
- set delete_xref 1}
- default {
- MH_InfoDialog . "Error: Unrecognised clear command"
- return
- }
- }
-
- # Get the selected text, and unformat
- if [catch {$gt_mini_help get sel.first}] {return}
- set this [$gt_mini_help index sel.first]
- set last [$gt_mini_help index sel.last]
- while {$this != $last} {
-
- # Delete selected formatting commands
- foreach tag $al_del_list {
- #MH_InfoDialog . "Removing $tag from position $this"
- $gt_mini_help tag remove $tag $this
- }
- # If delete_xref selected find the xrefs and delete
- if {$delete_xref == 1} {
- set tags [$gt_mini_help tag names $this]
- foreach tag $as_non_xref {
- set loc [lsearch -exact $tags $tag]
- if {$loc != -1} {set tags [lreplace $tags $loc $loc]}
- }
- foreach xref $tags {
- #MH_InfoDialog . "Removing xref $tag from position $this"
- $gt_mini_help tag remove $xref $this
- }
- }
-
- # Increment to the next character
- set this [$gt_mini_help index "$this + 1 chars"]
- }
-
- # And allow a save
- set gb_project_changed 1
- set gb_current_page_changed 1
- .name_fr.save configure -state normal
- }
-
- ###############################################################
- # Show the main interface
- ###############################################################
-
- # Source other files
- MH_SourceOther MiniHelp_Runtime.tcl
-
- # Create the mini-help screen
- wm title . "Edit Help - <no project>"
- wm geometry . $TKNET_HELP_GEOMETRY
- wm protocol . WM_DELETE_WINDOW "MH_CloseProject 1"
-
- ###########################################################################
- # Create Menu Bar
- frame .mbar -relief raised -bd 2
- pack .mbar -side top -fill x
-
- # Create the buttons
- menubutton .mbar.file -text File -underline 0 -menu .mbar.file.menu
- menubutton .mbar.edit -text Edit -underline 0 -menu .mbar.edit.menu
- menubutton .mbar.format -text Format -underline 0 -menu .mbar.format.menu
- menubutton .mbar.justify -text Justify -underline 0 -menu .mbar.justify.menu
- menubutton .mbar.page -text Page -underline 0 -menu .mbar.page.menu
- menubutton .mbar.navigate -text Navigate -underline 0 -menu .mbar.navigate.menu
- menubutton .mbar.options -text Options -underline 0 -menu .mbar.options.menu
- pack .mbar.file .mbar.edit .mbar.format .mbar.justify .mbar.page \
- .mbar.navigate .mbar.options -side left
-
- # Create each menu item
- menu .mbar.file.menu -tearoff 0
- .mbar.file.menu add command -label "Open" -command \
- "MH_OpenProject" -underline 0 -accelerator "Ctrl-O"
- .mbar.file.menu add command -label "Close" -command \
- "MH_CloseProject 0" -underline 0
- .mbar.file.menu add separator
- .mbar.file.menu add command -label "Save" -command \
- {MH_SaveProject $gs_current_project} -underline 0
- .mbar.file.menu add command -label "Save As..." -command "MH_SaveProjectAs" -underline 0
- .mbar.file.menu add separator
- .mbar.file.menu add command -label "Exit" -command "MH_CloseProject 1" -underline 0
- menu .mbar.edit.menu -tearoff 0
- .mbar.edit.menu add command -label "Cut" -command \
- "MH_CopyText 1" -underline 2 -accelerator "Ctrl-X"
- .mbar.edit.menu add command -label "Copy" -command \
- "MH_CopyText 0" -underline 0 -accelerator "Ctrl-C"
- .mbar.edit.menu add command -label "Paste" -command \
- "MH_PasteText" -underline 0 -accelerator "Ctrl-V"
- .mbar.edit.menu add separator
- .mbar.edit.menu add command -label "Remove Link" -command \
- "MH_RemoveTags XREF" -underline 0
- .mbar.edit.menu add command -label "Remove Formatting" -command \
- "MH_RemoveTags CHARACTER" -underline 0
- .mbar.edit.menu add command -label "Remove Justification" -command \
- "MH_RemoveTags JUSTIFY" -underline 0
- .mbar.edit.menu add command -label "Remove All" -command \
- "MH_RemoveTags ALL" -underline 0
- menu .mbar.format.menu -tearoff 0
- .mbar.format.menu add command -label Bold -command "MH_AddTag BOLD" \
- -underline 0 -accelerator "Ctrl-B"
- .mbar.format.menu add command -label Italic -command \
- "MH_AddTag ITALIC" -underline 0 -accelerator "Ctrl-I"
- .mbar.format.menu add command -label Underline -command \
- "MH_AddTag UNDERLINE" -underline 0 -accelerator "Ctrl-U"
- .mbar.format.menu add command -label Serif -command \
- "MH_AddTag FIXED" -underline 0 -accelerator "Ctrl-S"
- .mbar.format.menu add separator
- .mbar.format.menu add command -label Title -command \
- "MH_AddTag TITLE" -underline 0 -accelerator "Ctrl-T"
- .mbar.format.menu add command -label Hyperlink... -command \
- {MH_BindLink "" "" ""} -underline 0 -accelerator "Ctrl-L"
- menu .mbar.justify.menu -tearoff 0
- .mbar.justify.menu add command -label Centre -command \
- "MH_AddTag CENTER" -underline 0
- .mbar.justify.menu add command -label Left -command \
- "MH_AddTag LEFT" -underline 0
- .mbar.justify.menu add command -label Right -command \
- "MH_AddTag RIGHT" -underline 0
- menu .mbar.page.menu -tearoff 0
- .mbar.page.menu add command -label New -command {
- if {$gb_current_page_changed == 0 || $gb_page_autocommit == 1} {
- MH_SaveHelpPage
- MH_NewHelpPage
- } else {
- if ![MH_QuestionDialog . "Help text on this page has changed!" \
- "Discard Changes" "Cancel"] {
- MH_NewHelpPage
- }
- }
- } -underline 0
- .mbar.page.menu add command -label "Rename ..." -command \
- {MH_RenamePage} -underline 0
- .mbar.page.menu add command -label Delete -command {
- set name [.name_fr.name get]
- if {$name != ""} {
- MH_DeleteHelpPage $name
- }
- } -underline 0
- .mbar.page.menu add separator
- .mbar.page.menu add checkbutton -label "Display Formatted" -command {
- if {$gb_show_formatted == 1} {
- MH_ParseHelp 0
- } else {
- MH_Create_Help
- }
- } -variable gb_show_formatted
- menu .mbar.navigate.menu -tearoff 0
- .mbar.navigate.menu add command -label "Previous Page" -command {
- if {$gb_current_page_changed == 0 || $gb_page_autocommit == 1} {
- MH_SaveHelpPage
- MH_EditNavigateBack
- } else {
- if ![MH_QuestionDialog . "Help text on this page has changed!" \
- "Discard Changes" "Cancel"] {
- MH_EditNavigateBack
- }
- }
- } -underline 0 -accelerator "Ctrl-P"
- .mbar.navigate.menu add command -label "History ..." -command {
- if {$gb_current_page_changed == 0 || $gb_page_autocommit == 1} {
- MH_SaveHelpPage
- MH_SelectHelpPage HISTORY
- } else {
- if ![MH_QuestionDialog . "Help text on this page has changed!" \
- "Discard Changes" "Cancel"] {
- MH_SelectHelpPage HISTORY
- }
- }
- } -underline 0 -accelerator "Ctrl-H"
- .mbar.navigate.menu add command -label "Select Page ..." -command {
- if {$gb_current_page_changed == 0 || $gb_page_autocommit == 1} {
- MH_SaveHelpPage
- MH_SelectHelpPage FULL
- } else {
- if ![MH_QuestionDialog . "Help text on this page has changed!" \
- "Discard Changes" "Cancel"] {
- MH_SelectHelpPage FULL
- }
- }
- } -underline 0 -accelerator "Ctrl-G"
- menu .mbar.options.menu -tearoff 0
- .mbar.options.menu add checkbutton -label "Autocommit Pages" \
- -variable gb_page_autocommit
-
- # Create the menu
- tk_menuBar .mbar .mbar.file .mbar.edit .mbar.format \
- .mbar.justify .mbar.page .mbar.navigate
-
- ###############################################################
- # Create the page label
- set frame [frame .name_fr -relief groove -borderwidth $RIDGE_BORDER]
- label $frame.label -text "Page Label"
- entry $frame.name -width 25 -state disabled
- button $frame.save -text Save -command {MH_SaveHelpPage}
- $frame.save configure -state disabled -disabledforeground ""
- button $frame.open -text "..." -command {
- if {$gb_current_page_changed == 0 || $gb_page_autocommit == 1} {
- MH_SaveHelpPage
- MH_SelectHelpPage FULL
- } else {
- if ![MH_QuestionDialog . "Help text on this page has changed!" \
- "Discard Changes" "Cancel"] {
- MH_SelectHelpPage FULL
- }
- }
- }
- pack $frame.label $frame.name $frame.open $frame.save -side left \
- -fill x -padx $DEFAULT_PADDING -pady $DEFAULT_PADDING
- pack $frame -padx $DEFAULT_PADDING -pady $DEFAULT_PADDING -fill x
-
- ###############################################################
- # Create the text widget
- frame .fr -borderwidth $RIDGE_BORDER -relief groove
- pack .fr -padx $DEFAULT_PADDING -pady $DEFAULT_PADDING -side top \
- -expand true -fill both
- set gt_mini_help [MH_ScrolledText .fr.help 70 20 0]
- $gt_mini_help configure -font $FONT_NORMAL -bg $TEXT_COLOUR -state \
- disabled
- $gt_mini_help tag bind sel <3> {+MH_PopupMenu $gt_mini_help .mbar.format.menu}
- $gt_mini_help tag bind sel <Control-3> {+MH_PopupMenu $gt_mini_help .mbar.edit.menu}
- $gt_mini_help tag bind sel <Shift-3> {+MH_PopupMenu $gt_mini_help .mbar.justify.menu}
- bind $gt_mini_help <KeyPress> {
- set gb_current_page_changed 1
- set gb_project_changed 1
- $frame.save configure -state normal
- }
- pack .fr.help -side top -anchor w
-
- # Pop-up the open dialogue
- MH_OpenProject
-